﻿using System;
using Microsoft.Xna.Framework;

namespace Terraria
{
	// Token: 0x0200004F RID: 79
	public class Tile
	{
		// Token: 0x170000B7 RID: 183
		// (get) Token: 0x060006CE RID: 1742 RVA: 0x0036AE6C File Offset: 0x0036906C
		public int collisionType
		{
			get
			{
				if (!this.active())
				{
					return 0;
				}
				if (this.halfBrick())
				{
					return 2;
				}
				if (this.slope() > 0)
				{
					return (int)(2 + this.slope());
				}
				if (Main.tileSolid[(int)this.type] && !Main.tileSolidTop[(int)this.type])
				{
					return 1;
				}
				return -1;
			}
		}

		// Token: 0x060006CF RID: 1743 RVA: 0x0036AEC0 File Offset: 0x003690C0
		public Tile()
		{
			this.type = 0;
			this.wall = 0;
			this.liquid = 0;
			this.sTileHeader = 0;
			this.bTileHeader = 0;
			this.bTileHeader2 = 0;
			this.bTileHeader3 = 0;
			this.frameX = 0;
			this.frameY = 0;
		}

		// Token: 0x060006D0 RID: 1744 RVA: 0x0036AF14 File Offset: 0x00369114
		public Tile(Tile copy)
		{
			if (copy == null)
			{
				this.type = 0;
				this.wall = 0;
				this.liquid = 0;
				this.sTileHeader = 0;
				this.bTileHeader = 0;
				this.bTileHeader2 = 0;
				this.bTileHeader3 = 0;
				this.frameX = 0;
				this.frameY = 0;
				return;
			}
			this.type = copy.type;
			this.wall = copy.wall;
			this.liquid = copy.liquid;
			this.sTileHeader = copy.sTileHeader;
			this.bTileHeader = copy.bTileHeader;
			this.bTileHeader2 = copy.bTileHeader2;
			this.bTileHeader3 = copy.bTileHeader3;
			this.frameX = copy.frameX;
			this.frameY = copy.frameY;
		}

		// Token: 0x060006D1 RID: 1745 RVA: 0x000064EA File Offset: 0x000046EA
		public object Clone()
		{
			return base.MemberwiseClone();
		}

		// Token: 0x060006D2 RID: 1746 RVA: 0x0036AFD8 File Offset: 0x003691D8
		public void ClearEverything()
		{
			this.type = 0;
			this.wall = 0;
			this.liquid = 0;
			this.sTileHeader = 0;
			this.bTileHeader = 0;
			this.bTileHeader2 = 0;
			this.bTileHeader3 = 0;
			this.frameX = 0;
			this.frameY = 0;
		}

		// Token: 0x060006D3 RID: 1747 RVA: 0x000093AE File Offset: 0x000075AE
		public void ClearTile()
		{
			this.slope(0);
			this.halfBrick(false);
			this.active(false);
		}

		// Token: 0x060006D4 RID: 1748 RVA: 0x0036B024 File Offset: 0x00369224
		public void CopyFrom(Tile from)
		{
			this.type = from.type;
			this.wall = from.wall;
			this.liquid = from.liquid;
			this.sTileHeader = from.sTileHeader;
			this.bTileHeader = from.bTileHeader;
			this.bTileHeader2 = from.bTileHeader2;
			this.bTileHeader3 = from.bTileHeader3;
			this.frameX = from.frameX;
			this.frameY = from.frameY;
		}

		// Token: 0x060006D5 RID: 1749 RVA: 0x0036B0A0 File Offset: 0x003692A0
		public bool isTheSameAs(Tile compTile)
		{
			if (compTile == null)
			{
				return false;
			}
			if (this.sTileHeader != compTile.sTileHeader)
			{
				return false;
			}
			if (this.active())
			{
				if (this.type != compTile.type)
				{
					return false;
				}
				if (Main.tileFrameImportant[(int)this.type] && (this.frameX != compTile.frameX || this.frameY != compTile.frameY))
				{
					return false;
				}
			}
			if (this.wall != compTile.wall || this.liquid != compTile.liquid)
			{
				return false;
			}
			if (compTile.liquid == 0)
			{
				if (this.wallColor() != compTile.wallColor())
				{
					return false;
				}
				if (this.wire4() != compTile.wire4())
				{
					return false;
				}
			}
			else if (this.bTileHeader != compTile.bTileHeader)
			{
				return false;
			}
			return true;
		}

		// Token: 0x060006D6 RID: 1750 RVA: 0x0036B160 File Offset: 0x00369360
		public int blockType()
		{
			if (this.halfBrick())
			{
				return 1;
			}
			int num = (int)this.slope();
			if (num > 0)
			{
				num++;
			}
			return num;
		}

		// Token: 0x060006D7 RID: 1751 RVA: 0x000093C5 File Offset: 0x000075C5
		public void liquidType(int liquidType)
		{
			if (liquidType == 0)
			{
				this.bTileHeader &= 159;
				return;
			}
			if (liquidType == 1)
			{
				this.lava(true);
				return;
			}
			if (liquidType == 2)
			{
				this.honey(true);
			}
		}

		// Token: 0x060006D8 RID: 1752 RVA: 0x000093F5 File Offset: 0x000075F5
		public byte liquidType()
		{
			return (byte)((this.bTileHeader & 96) >> 5);
		}

		// Token: 0x060006D9 RID: 1753 RVA: 0x0036B188 File Offset: 0x00369388
		public bool nactive()
		{
			int num = (int)(this.sTileHeader & 96);
			return num == 32;
		}

		// Token: 0x060006DA RID: 1754 RVA: 0x00009403 File Offset: 0x00007603
		public void ResetToType(ushort type)
		{
			this.liquid = 0;
			this.sTileHeader = 32;
			this.bTileHeader = 0;
			this.bTileHeader2 = 0;
			this.bTileHeader3 = 0;
			this.frameX = 0;
			this.frameY = 0;
			this.type = type;
		}

		// Token: 0x060006DB RID: 1755 RVA: 0x0000943E File Offset: 0x0000763E
		internal void ClearMetadata()
		{
			this.liquid = 0;
			this.sTileHeader = 0;
			this.bTileHeader = 0;
			this.bTileHeader2 = 0;
			this.bTileHeader3 = 0;
			this.frameX = 0;
			this.frameY = 0;
		}

		// Token: 0x060006DC RID: 1756 RVA: 0x0036B1A4 File Offset: 0x003693A4
		public Color actColor(Color oldColor)
		{
			if (!this.inActive())
			{
				return oldColor;
			}
			double num = 0.4;
			return new Color((int)((byte)(num * (double)oldColor.R)), (int)((byte)(num * (double)oldColor.G)), (int)((byte)(num * (double)oldColor.B)), (int)oldColor.A);
		}

		// Token: 0x060006DD RID: 1757 RVA: 0x0036B1F4 File Offset: 0x003693F4
		public bool topSlope()
		{
			byte b = this.slope();
			return b == 1 || b == 2;
		}

		// Token: 0x060006DE RID: 1758 RVA: 0x0036B214 File Offset: 0x00369414
		public bool bottomSlope()
		{
			byte b = this.slope();
			return b == 3 || b == 4;
		}

		// Token: 0x060006DF RID: 1759 RVA: 0x0036B234 File Offset: 0x00369434
		public bool leftSlope()
		{
			byte b = this.slope();
			return b == 2 || b == 4;
		}

		// Token: 0x060006E0 RID: 1760 RVA: 0x0036B254 File Offset: 0x00369454
		public bool rightSlope()
		{
			byte b = this.slope();
			return b == 1 || b == 3;
		}

		// Token: 0x060006E1 RID: 1761 RVA: 0x00009471 File Offset: 0x00007671
		public bool HasSameSlope(Tile tile)
		{
			return (this.sTileHeader & 29696) == (tile.sTileHeader & 29696);
		}

		// Token: 0x060006E2 RID: 1762 RVA: 0x0000948D File Offset: 0x0000768D
		public byte wallColor()
		{
			return this.bTileHeader & 31;
		}

		// Token: 0x060006E3 RID: 1763 RVA: 0x00009499 File Offset: 0x00007699
		public void wallColor(byte wallColor)
		{
			if (wallColor > 30)
			{
				wallColor = 30;
			}
			this.bTileHeader = ((this.bTileHeader & 224) | wallColor);
		}

		// Token: 0x060006E4 RID: 1764 RVA: 0x000094B9 File Offset: 0x000076B9
		public bool lava()
		{
			return (this.bTileHeader & 32) == 32;
		}

		// Token: 0x060006E5 RID: 1765 RVA: 0x000094C8 File Offset: 0x000076C8
		public void lava(bool lava)
		{
			if (lava)
			{
				this.bTileHeader = ((this.bTileHeader & 159) | 32);
				return;
			}
			this.bTileHeader &= 223;
		}

		// Token: 0x060006E6 RID: 1766 RVA: 0x000094F7 File Offset: 0x000076F7
		public bool honey()
		{
			return (this.bTileHeader & 64) == 64;
		}

		// Token: 0x060006E7 RID: 1767 RVA: 0x00009506 File Offset: 0x00007706
		public void honey(bool honey)
		{
			if (honey)
			{
				this.bTileHeader = ((this.bTileHeader & 159) | 64);
				return;
			}
			this.bTileHeader &= 191;
		}

		// Token: 0x060006E8 RID: 1768 RVA: 0x00009535 File Offset: 0x00007735
		public bool wire4()
		{
			return (this.bTileHeader & 128) == 128;
		}

		// Token: 0x060006E9 RID: 1769 RVA: 0x0000954A File Offset: 0x0000774A
		public void wire4(bool wire4)
		{
			if (wire4)
			{
				this.bTileHeader |= 128;
				return;
			}
			this.bTileHeader &= 127;
		}

		// Token: 0x060006EA RID: 1770 RVA: 0x00009573 File Offset: 0x00007773
		public int wallFrameX()
		{
			return (int)((this.bTileHeader2 & 15) * 36);
		}

		// Token: 0x060006EB RID: 1771 RVA: 0x00009581 File Offset: 0x00007781
		public void wallFrameX(int wallFrameX)
		{
			this.bTileHeader2 = (byte)((int)(this.bTileHeader2 & 240) | (wallFrameX / 36 & 15));
		}

		// Token: 0x060006EC RID: 1772 RVA: 0x0000959E File Offset: 0x0000779E
		public byte frameNumber()
		{
			return (byte)((this.bTileHeader2 & 48) >> 4);
		}

		// Token: 0x060006ED RID: 1773 RVA: 0x000095AC File Offset: 0x000077AC
		public void frameNumber(byte frameNumber)
		{
			this.bTileHeader2 = (byte)((int)(this.bTileHeader2 & 207) | (int)(frameNumber & 3) << 4);
		}

		// Token: 0x060006EE RID: 1774 RVA: 0x000095C7 File Offset: 0x000077C7
		public byte wallFrameNumber()
		{
			return (byte)((this.bTileHeader2 & 192) >> 6);
		}

		// Token: 0x060006EF RID: 1775 RVA: 0x000095D8 File Offset: 0x000077D8
		public void wallFrameNumber(byte wallFrameNumber)
		{
			this.bTileHeader2 = (byte)((int)(this.bTileHeader2 & 63) | (int)(wallFrameNumber & 3) << 6);
		}

		// Token: 0x060006F0 RID: 1776 RVA: 0x000095F0 File Offset: 0x000077F0
		public int wallFrameY()
		{
			return (int)((this.bTileHeader3 & 7) * 36);
		}

		// Token: 0x060006F1 RID: 1777 RVA: 0x000095FD File Offset: 0x000077FD
		public void wallFrameY(int wallFrameY)
		{
			this.bTileHeader3 = (byte)((int)(this.bTileHeader3 & 248) | (wallFrameY / 36 & 7));
		}

		// Token: 0x060006F2 RID: 1778 RVA: 0x00009619 File Offset: 0x00007819
		public bool checkingLiquid()
		{
			return (this.bTileHeader3 & 8) == 8;
		}

		// Token: 0x060006F3 RID: 1779 RVA: 0x00009626 File Offset: 0x00007826
		public void checkingLiquid(bool checkingLiquid)
		{
			if (checkingLiquid)
			{
				this.bTileHeader3 |= 8;
				return;
			}
			this.bTileHeader3 &= 247;
		}

		// Token: 0x060006F4 RID: 1780 RVA: 0x0000964E File Offset: 0x0000784E
		public bool skipLiquid()
		{
			return (this.bTileHeader3 & 16) == 16;
		}

		// Token: 0x060006F5 RID: 1781 RVA: 0x0000965D File Offset: 0x0000785D
		public void skipLiquid(bool skipLiquid)
		{
			if (skipLiquid)
			{
				this.bTileHeader3 |= 16;
				return;
			}
			this.bTileHeader3 &= 239;
		}

		// Token: 0x060006F6 RID: 1782 RVA: 0x00009686 File Offset: 0x00007886
		public byte color()
		{
			return (byte)(this.sTileHeader & 31);
		}

		// Token: 0x060006F7 RID: 1783 RVA: 0x00009692 File Offset: 0x00007892
		public void color(byte color)
		{
			if (color > 30)
			{
				color = 30;
			}
			this.sTileHeader = ((this.sTileHeader & 65504) | (ushort)color);
		}

		// Token: 0x060006F8 RID: 1784 RVA: 0x000096B2 File Offset: 0x000078B2
		public bool active()
		{
			return (this.sTileHeader & 32) == 32;
		}

		// Token: 0x060006F9 RID: 1785 RVA: 0x000096C1 File Offset: 0x000078C1
		public void active(bool active)
		{
			if (active)
			{
				this.sTileHeader |= 32;
				return;
			}
			this.sTileHeader &= 65503;
		}

		// Token: 0x060006FA RID: 1786 RVA: 0x000096EA File Offset: 0x000078EA
		public bool inActive()
		{
			return (this.sTileHeader & 64) == 64;
		}

		// Token: 0x060006FB RID: 1787 RVA: 0x000096F9 File Offset: 0x000078F9
		public void inActive(bool inActive)
		{
			if (inActive)
			{
				this.sTileHeader |= 64;
				return;
			}
			this.sTileHeader &= 65471;
		}

		// Token: 0x060006FC RID: 1788 RVA: 0x00009722 File Offset: 0x00007922
		public bool wire()
		{
			return (this.sTileHeader & 128) == 128;
		}

		// Token: 0x060006FD RID: 1789 RVA: 0x00009737 File Offset: 0x00007937
		public void wire(bool wire)
		{
			if (wire)
			{
				this.sTileHeader |= 128;
				return;
			}
			this.sTileHeader &= 65407;
		}

		// Token: 0x060006FE RID: 1790 RVA: 0x00009763 File Offset: 0x00007963
		public bool wire2()
		{
			return (this.sTileHeader & 256) == 256;
		}

		// Token: 0x060006FF RID: 1791 RVA: 0x00009778 File Offset: 0x00007978
		public void wire2(bool wire2)
		{
			if (wire2)
			{
				this.sTileHeader |= 256;
				return;
			}
			this.sTileHeader &= 65279;
		}

		// Token: 0x06000700 RID: 1792 RVA: 0x000097A4 File Offset: 0x000079A4
		public bool wire3()
		{
			return (this.sTileHeader & 512) == 512;
		}

		// Token: 0x06000701 RID: 1793 RVA: 0x000097B9 File Offset: 0x000079B9
		public void wire3(bool wire3)
		{
			if (wire3)
			{
				this.sTileHeader |= 512;
				return;
			}
			this.sTileHeader &= 65023;
		}

		// Token: 0x06000702 RID: 1794 RVA: 0x000097E5 File Offset: 0x000079E5
		public bool halfBrick()
		{
			return (this.sTileHeader & 1024) == 1024;
		}

		// Token: 0x06000703 RID: 1795 RVA: 0x000097FA File Offset: 0x000079FA
		public void halfBrick(bool halfBrick)
		{
			if (halfBrick)
			{
				this.sTileHeader |= 1024;
				return;
			}
			this.sTileHeader &= 64511;
		}

		// Token: 0x06000704 RID: 1796 RVA: 0x00009826 File Offset: 0x00007A26
		public bool actuator()
		{
			return (this.sTileHeader & 2048) == 2048;
		}

		// Token: 0x06000705 RID: 1797 RVA: 0x0000983B File Offset: 0x00007A3B
		public void actuator(bool actuator)
		{
			if (actuator)
			{
				this.sTileHeader |= 2048;
				return;
			}
			this.sTileHeader &= 63487;
		}

		// Token: 0x06000706 RID: 1798 RVA: 0x00009867 File Offset: 0x00007A67
		public byte slope()
		{
			return (byte)((this.sTileHeader & 28672) >> 12);
		}

		// Token: 0x06000707 RID: 1799 RVA: 0x00009879 File Offset: 0x00007A79
		public void slope(byte slope)
		{
			this.sTileHeader = (ushort)((int)(this.sTileHeader & 36863) | (int)(slope & 7) << 12);
		}

		// Token: 0x06000708 RID: 1800 RVA: 0x0036B274 File Offset: 0x00369474
		public static void SmoothSlope(int x, int y, bool applyToNeighbors = true)
		{
			if (applyToNeighbors)
			{
				Tile.SmoothSlope(x + 1, y, false);
				Tile.SmoothSlope(x - 1, y, false);
				Tile.SmoothSlope(x, y + 1, false);
				Tile.SmoothSlope(x, y - 1, false);
			}
			Tile tile = Main.tile[x, y];
			if (!WorldGen.SolidOrSlopedTile(x, y))
			{
				return;
			}
			bool flag = !WorldGen.TileEmpty(x, y - 1);
			bool flag2 = !WorldGen.SolidOrSlopedTile(x, y - 1) && flag;
			bool flag3 = WorldGen.SolidOrSlopedTile(x, y + 1);
			bool flag4 = WorldGen.SolidOrSlopedTile(x - 1, y);
			bool flag5 = WorldGen.SolidOrSlopedTile(x + 1, y);
			switch ((flag ? 1 : 0) << 3 | (flag3 ? 1 : 0) << 2 | (flag4 ? 1 : 0) << 1 | (flag5 ? 1 : 0))
			{
			case 4:
				tile.slope(0);
				tile.halfBrick(true);
				return;
			case 5:
				tile.halfBrick(false);
				tile.slope(2);
				return;
			case 6:
				tile.halfBrick(false);
				tile.slope(1);
				return;
			case 9:
				if (!flag2)
				{
					tile.halfBrick(false);
					tile.slope(4);
					return;
				}
				return;
			case 10:
				if (!flag2)
				{
					tile.halfBrick(false);
					tile.slope(3);
					return;
				}
				return;
			}
			tile.halfBrick(false);
			tile.slope(0);
		}

		// Token: 0x06000709 RID: 1801 RVA: 0x0036B3B0 File Offset: 0x003695B0
		public override string ToString()
		{
			return string.Concat(new object[]
			{
				"Tile Type:",
				this.type,
				" Active:",
				this.active(),
				" Wall:",
				this.wall,
				" Slope:",
				this.slope(),
				" fX:",
				this.frameX,
				" fY:",
				this.frameY
			});
		}

		// Token: 0x04000CE3 RID: 3299
		public const int Type_Solid = 0;

		// Token: 0x04000CE4 RID: 3300
		public const int Type_Halfbrick = 1;

		// Token: 0x04000CE5 RID: 3301
		public const int Type_SlopeDownRight = 2;

		// Token: 0x04000CE6 RID: 3302
		public const int Type_SlopeDownLeft = 3;

		// Token: 0x04000CE7 RID: 3303
		public const int Type_SlopeUpRight = 4;

		// Token: 0x04000CE8 RID: 3304
		public const int Type_SlopeUpLeft = 5;

		// Token: 0x04000CE9 RID: 3305
		public const int Liquid_Water = 0;

		// Token: 0x04000CEA RID: 3306
		public const int Liquid_Lava = 1;

		// Token: 0x04000CEB RID: 3307
		public const int Liquid_Honey = 2;

		// Token: 0x04000CEC RID: 3308
		public ushort type;

		// Token: 0x04000CED RID: 3309
		public ushort wall;

		// Token: 0x04000CEE RID: 3310
		public byte liquid;

		// Token: 0x04000CEF RID: 3311
		public ushort sTileHeader;

		// Token: 0x04000CF0 RID: 3312
		public byte bTileHeader;

		// Token: 0x04000CF1 RID: 3313
		public byte bTileHeader2;

		// Token: 0x04000CF2 RID: 3314
		public byte bTileHeader3;

		// Token: 0x04000CF3 RID: 3315
		public short frameX;

		// Token: 0x04000CF4 RID: 3316
		public short frameY;
	}
}
